<?php

namespace common\models\db;

use Yii;

/**
 * This is the model class for table "tbl_loan_comparison".
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property int $record1_id 对比的第一条记录ID
 * @property int $record2_id 对比的第二条记录ID
 * @property string|null $conclusion 对比结论
 * @property string $created_at 创建时间
 *
 * @property LoanRecord $record1
 * @property LoanRecord $record2
 * @property User $user
 */
class LoanComparison extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'tbl_loan_comparison';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id', 'record1_id', 'record2_id'], 'required'],
            [['user_id', 'record1_id', 'record2_id'], 'integer'],
            [['conclusion'], 'string'],
            [['created_at'], 'safe'],
            [['record1_id'], 'exist', 'skipOnError' => true, 'targetClass' => LoanRecord::class, 'targetAttribute' => ['record1_id' => 'id']],
            [['record2_id'], 'exist', 'skipOnError' => true, 'targetClass' => LoanRecord::class, 'targetAttribute' => ['record2_id' => 'id']],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'record1_id' => 'Record1 ID',
            'record2_id' => 'Record2 ID',
            'conclusion' => 'Conclusion',
            'created_at' => 'Created At',
        ];
    }

    /**
     * Gets query for [[Record1]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getRecord1()
    {
        return $this->hasOne(LoanRecord::class, ['id' => 'record1_id']);
    }

    /**
     * Gets query for [[Record2]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getRecord2()
    {
        return $this->hasOne(LoanRecord::class, ['id' => 'record2_id']);
    }

    /**
     * Gets query for [[User]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::class, ['id' => 'user_id']);
    }
}
